package cn.tedu.egarticle.base.interceptors;

import cn.tedu.egarticle.pojo.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("登录转态拦截器preHandle方法执行");
        //获取会话seesion
        HttpSession session = request.getSession();
        UserVO userVO = (UserVO) session.getAttribute("user777888XXX");
        if (userVO == null) {
            //用户未登录,重定向
            response.sendRedirect("/login.html");
            return false;
        }else {
            //用户已登录
            return true;
        }
    }
}
